package com.yshkj.payment.entity;

import org.springframework.security.core.GrantedAuthority;

import javax.persistence.*;

/**
 * 用户权限中间表<br>
 * 用户用户账号和权限之间的关联<br>
 * 一个账号有多个权限,一个权限可以对应多个账号<br>
 * 实际上就是<code>@ManyToMany</code><br>
 * Created by 唐旭 on 2016/9/7.
 */
@Entity
@Table
public class UserPrivilege extends BaseDomain implements GrantedAuthority {
    @ManyToOne
    @JoinColumn(name = "user_account")
    private UserAccount userAccount;

    @ManyToOne
    @JoinColumn(name = "user_role")
    private UserRole userRole;

    @ManyToOne
    @JoinColumn(name = "privilege")
    private Privilege privilege;

    public UserPrivilege() {
    }

    public UserPrivilege(UserAccount userAccount) {
        this.userAccount = userAccount;
    }

    public UserPrivilege(UserRole userRole) {
        this.userRole = userRole;
    }

    public UserAccount getUserAccount() {
        return userAccount;
    }

    public UserPrivilege setUserAccount(UserAccount userAccount) {
        this.userAccount = userAccount;
        return this;
    }

    public Privilege getPrivilege() {
        return privilege;
    }

    public UserPrivilege setPrivilege(Privilege privilege) {
        this.privilege = privilege;
        return this;
    }

    public UserRole getUserRole() {
        return userRole;
    }

    public UserPrivilege setUserRole(UserRole userRole) {
        this.userRole = userRole;
        return this;
    }

    @Override
    public String getAuthority() {
        return privilege.getName();
    }
}
